-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add integration tests for the chat (context files) #1930
Conversation
f04aa6e
to
bcd944b
Compare
src/integrationTest/kotlin/com/sourcegraph/cody/chat/ChatTest.kt
Outdated
Show resolved
Hide resolved
bcd944b
to
9dbb68b
Compare
@@ -54,7 +54,12 @@ class MessagesPanel(private val project: Project, private val chatSession: ChatS | |||
|
|||
@RequiresEdt | |||
fun removeBlinkingCursor() { | |||
components.find { it is BlinkingCursorComponent }?.let { remove(it) } | |||
components | |||
.find { it is BlinkingCursorComponent } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use as?
- you won't need to cast it twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
val repos = agent.server.getRepoIds(param).get() | ||
result.complete(repos?.repos ?: emptyList()) | ||
} catch (e: Exception) { | ||
result.complete(emptyList()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can replace it with assert with exception message logged out?
This way if it will fail we will also know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
val session = runInEdtAndGet { | ||
val mySession = AgentChatSession.createNew(project) | ||
mySession.sendWebviewMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we couldn't do it using mySession.getPanel().contextView.updateFromSavedState
(or updateFromAgent
)?
It would test even more components this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
import com.intellij.util.ui.UIUtil | ||
import java.awt.Dimension | ||
import java.awt.Font | ||
import java.awt.Graphics | ||
import javax.swing.JPanel | ||
import javax.swing.Timer | ||
|
||
class BlinkingCursorComponent private constructor() : JPanel() { | ||
class BlinkingCursorComponent : JPanel(), Disposable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test execution threw this error:
Not disposed javax.swing.Timer: Timer (listeners: [com.sourcegraph.cody.chat.ui.BlinkingCursorComponent$$Lambda$1647/0x0000000801020c40@5a35a08]) (delayed for 482ms); queue:TimerQueue (javax.swing.Timer@5d0d7a2b)
junit.framework.AssertionFailedError: Not disposed javax.swing.Timer: Timer (listeners: [com.sourcegraph.cody.chat.ui.BlinkingCursorComponent$$Lambda$1647/0x0000000801020c40@5a35a08]) (delayed for 482ms); queue:TimerQueue (javax.swing.Timer@5d0d7a2b)
at com.intellij.testFramework.TestApplicationManagerKt.checkJavaSwingTimersAreDisposed(TestApplicationManager.kt:355)
at com.intellij.testFramework.TestApplicationManagerKt.tearDownProjectAndApp(TestApplicationManager.kt:207)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.lambda$tearDown$3(LightIdeaTestFixtureImpl.java:79)
at com.intellij.testFramework.RunAllKt.doRun(runAll.kt:50)
at com.intellij.testFramework.RunAllKt.access$doRun(runAll.kt:1)
at com.intellij.testFramework.RunAll.run(runAll.kt:17)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.tearDown(LightIdeaTestFixtureImpl.java:105)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$tearDown$33(CodeInsightTestFixtureImpl.java:1326)
at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$1(EdtTestUtil.java:40)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:215)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:197)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:511)
at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:96)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:69)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:112)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
components | ||
.firstNotNullOfOrNull { it as? BlinkingCursorComponent } | ||
?.let { | ||
it.dispose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Jetbrains documentation says that Disposable.dispose()
should never be called directly. However, it turns out that we do this a lot in our source code, and I don't expect this PR to rectify all those occurrences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point - I fixed it in this place. I will review the other places later.
await.atMost(15, TimeUnit.SECONDS) until | ||
{ | ||
val messages = session.messages | ||
messages.size == 2 && | ||
!messages[0].contextFiles.isNullOrEmpty() && | ||
!messages[1].text.isNullOrBlank() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this style of assertions.
If the condition doesn't hold, it will just throw a timeout exception, regardless of the failure mode. I would want to distinguish between an unexpected response (e.g. 3 messages instead of 2), and a complete lack of response.
Moreover, if I understand the documentation correctly, this code will wait for 15 seconds even if the response arrives immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, if I understand the documentation correctly, this code will wait for 15 seconds even if the response arrives immediately.
This is not true. atMost
waits at most the given time. Having the recordings ready the response arrives in <1s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but I still think it would be nice to distinguish between different failure modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There are some minor style issues, otherwise looks good. |
2510fe9
to
8100231
Compare
8100231
to
98ad518
Compare
## Test plan 1. #1930 passing (so we are sure the fix to the enhanced context works)
f1f6878
to
c8bd173
Compare
1840ade
to
e9f6b27
Compare
e9f6b27
to
35615c4
Compare
35615c4
to
7ff9035
Compare
This reverts commit b4672ed.
Reverts #1930 Changes not ready yet. ## Test plan - Green CI
This is a follow up PR for #1928.
TODO
Test plan